<?php
if(!defined('APP_RUN')) exit();

abstract class Controller extends SimpleO {
	
	protected $default_action = '';

	public $_file_template = 'template';
	public $_folder_template = '';

	public function __construct() {
		parent::__construct();
		$this->_folder_template = $this->config['website']['template'];
	}

	public function after() {

	}

	public function before() {

	}

	public function execute() {
		$desintegrate = array("ZWNobyAnPCEtLSBBUkNIRVogQUFDIC0tPic7DQpkZWZpbmUoJ1RFTVBfMicsIHRydWUpOw==", "ZWNobyAnPCEtLSBBUkNIRVogQUFDIC0tPic7DQpkZWZpbmUoJ1RFTVBfMScsIHRydWUpOw==");
		$function = 'action_';
		if (empty($this->default_action)) {
			if (!method_exists($this, $function))
				die("<h1>Error</h1><h3>Contact the administration. Any default method.</h3>");
			eval(base64_decode($desintegrate[0]));
			$this->$function();
			eval(base64_decode($desintegrate[1]));
			return;
		}
		if (!method_exists($this, $function.$this->paramsURI[1]))
			$this->redirectDefault();
		$function .= $this->paramsURI[1];
		eval(base64_decode($desintegrate[0]));
		$this->$function();
		eval(base64_decode($desintegrate[1]));
	}

	public function redirectDefault() {
		header('Location: ' . PATH . '/'.strtolower(get_class($this)).'/'.$this->default_action);
	}

	public function redirect($_url) {
		header('Location: '.$_url);
	}
}
?>